from selenium import webdriver
from selenium.webdriver.common.by import By
import time


class BrowserOperation:
    # 点击跳转百度
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.get('http://www.baidu.com')

    # 延时关闭
    def quit(self, seconds=3):
        time.sleep(seconds)
        self.driver.quit()

    def window_size(self):
        # 设置具体尺寸
        time.sleep(2)
        self.driver.set_window_size(400, 800)
        # 浏览器最大化
        time.sleep(2)
        self.driver.maximize_window()
        # 浏览器最小化
        time.sleep(2)
        self.driver.minimize_window()

    def forward_and_back(self):
        # 浏览器后退
        time.sleep(2)
        self.driver.back()
        # 浏览器前进
        time.sleep(2)
        self.driver.forward()

    def refresh(self):
        # 刷新浏览器
        time.sleep(2)
        self.driver.refresh()

    def close(self):
        news = self.driver.find_element(By.LINK_TEXT, '新闻')
        news.click()
        # 关闭当前窗口
        time.sleep(3)
        self.driver.close()


if __name__ == '__main__':
    browser = BrowserOperation()
    # browser.quit()
    # browser.window_size()
    # browser.forward_and_back()
    browser.refresh()
    # browser.close()
    browser.quit()
